package com.py.credit.clean.code;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

import com.py.credit.dao.RuleCheckingDao;

/**
 * 主体信息校验
 * @author Administrator
 *
 */

public class ZtxxCheck {
WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();


	private RuleCheckingDao ruleCheckingDao = context.getBean(RuleCheckingDao.class);

//    @Autowired
//    private RuleCheckingDao ruleCheckingDao;
    
	public  boolean run(Map<String, Object> map, String extend) {
		//自然人B000001,B000002,B000003
		
		if(String.valueOf(map.get("rootId")).equals("100001")) {
			//根据B000003获取主体信息
			Map<String,String> zrrdata = ruleCheckingDao.CheckType("t_10000190010_UNJNiQhGny","B000003",String.valueOf(map.get("B000003")));
			//判断主体信息是否匹配
			if(!CollectionUtils.isEmpty(zrrdata)) {
				if(!String.valueOf(map.get("B000001")).equals(zrrdata.get("B000001"))) {
					return false;
				}else {
					return true;
				}
			}
			
		}else if(String.valueOf(map.get("rootId")).equals("100000")){
			System.out.println(map.get("A000002"));
			//根据A000002获取主体信息
			Map<String,String> frdata = ruleCheckingDao.CheckType("t_100000460009_JnuqJ847ju","A000002",String.valueOf(map.get("A000002")));
			if(!CollectionUtils.isEmpty(frdata)) {
				//判断主体信息是否匹配
				if(!String.valueOf(map.get("A000001")).equals(frdata.get("A000001"))) {
					return false;
				}else if(String.valueOf(map.get("A000003"))!=null&&!String.valueOf(map.get("A000003")).equals("")){
					if(String.valueOf(frdata.get("A000003"))==null||String.valueOf(frdata.get("A000003")).equals("")) {
						return true;
					}else if(!String.valueOf(map.get("A000003")).equals(frdata.get("A000003"))) {
						return false;
					}
				
				}else {
					return true;
				}
			}
			
			
		}else if(String.valueOf(map.get("rootId")).equals("100002")){
			//根据C000002获取主体信息
			Map<String,String> ffrdata = ruleCheckingDao.CheckType("t_1000020010028_DEfBZD5dof","C000002",String.valueOf(map.get("C000002")));
			//判断主体信息是否匹配
			if(!CollectionUtils.isEmpty(ffrdata)) {
				if(!String.valueOf(map.get("C000001")).equals(ffrdata.get("C000001"))) {
					return false;
				}else if(String.valueOf(map.get("C000003"))!=null&&!String.valueOf(map.get("C000003")).equals("")){
					if(!String.valueOf(map.get("C000003")).equals(ffrdata.get("C000003"))) {
						return false;
					}
				
				}else {
					return true;
				}
			}
			
		}
			
		return true;
		
	

	}
	
}
